<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ include file="/jsp/common/common.jsp"%>  

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title></title>
		<meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
		<link rel="stylesheet" type="text/css" href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
		<link rel="stylesheet" type="text/css"
			href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
		<script type="text/javascript"
			src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
		<script type="text/javascript" src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>	
		<script type="text/javascript"
			src="<c:url value="/static/js/common.js"/>"></script>
		<script type="text/javascript"
            src="<c:url value="/static/js/LodopFuncs.js"/>"></script>   			
		<script>
	        
			function initList(listDisplayEId) {
				$('#' + listDisplayEId).datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							/* frozenColumns : [ [ {
								field : 'ids',
								checkbox : true
							} ] ], */
							toolbar : [
									{
										id : listDisplayEId + '_btn_add',
										text : '新增',
										iconCls : 'icon-add',
										handler : function() {
											var new_win =window.open("<c:url value='/jsp/openIndexSun.jsp?url=/mater/preSaveMater.do'/>","sun","width=1200px,height=600px,status=no,scrollbars=yes");
											new_win.focus();
											$('#'+listDisplayEId).datagrid('reload');
										}
									},'-',
									{
										id : listDisplayEId + '_btn_edit',
										text : '修改',
										iconCls : 'icon-edit',
										handler : function() {
										
											var row = $('#'+listDisplayEId).datagrid('getSelections');
 											if(row.length == 0){
												$.messager.alert('提示','请选择一条记录操作！','info');
												return;
											}else{
												var new_win = window.open("<c:url value='/jsp/openIndexSun.jsp?url=/mater/preUpdateMater.do'/>"+"?materId="+row[0]['materId']+"&materLevel="+row[0]['materLevel'] +"&supId="+row[0]['supId'] ,"sun","width=1200px,height=600px,status=no,scrollbars=yes");
												new_win.focus();
												$('#'+listDisplayEId).datagrid('reload');
											}
											$('#'+listDisplayEId).datagrid('clearSelections');
										}
									},
									{
										id : listDisplayEId + '_btn_del',
										text : '删除',
										iconCls : 'icon-cancel',
										handler : function() {
											
					                        var row = $('#'+listDisplayEId).datagrid('getSelections');		
										    if(row.length == 0){
												$.messager.alert('提示','请选择一条记录操作！','info');
												return;
											}else{
												var str = "materId=" + row[0]['materId']+"&materLevel=" + row[0]['materLevel']+"&supId=" + row[0]['supId'];	
  												$.messager.confirm('提示', '是否删除该条记录？', function(r){
													if (r){			
														$.ajax({type:'post',url:"<c:url value='/mater/deleteMater.do'/>",data:str,dataType:"json",//设置查询参数及提交路径
							 							success:function(data){
															if(data.success){
																$.messager.alert("提示", "删除成功！", 'info');
																$('#'+listDisplayEId).datagrid('reload');
															}else{
																$.messager.alert("提示", data.msg, 'warning');
															}
														},
									 					error:function(){
															$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
														}
													});
												}
												$('#'+listDisplayEId).datagrid('reload');
												$('#'+listDisplayEId).datagrid('clearSelections');
												});
											}
										}
									},
                                    {
                                        id : listDisplayEId + '_btn_del',
                                        text : '恢复',
                                        iconCls : 'icon-edit',
                                        handler : function() {
                                            
                                            var row = $('#'+listDisplayEId).datagrid('getSelections');      
                                            if(row.length == 0){
                                                $.messager.alert('提示','请选择一条记录操作！','info');
                                                return;
                                            }else{
                                                var str = "materId=" + row[0]['materId']+"&materLevel=" + row[0]['materLevel']+"&supId=" + row[0]['supId']; 
                                                $.messager.confirm('提示', '是否恢复该条记录？', function(r){
                                                    if (r){         
                                                        $.ajax({type:'post',url:"<c:url value='/mater/recoverMater.do'/>",data:str,dataType:"json",//设置查询参数及提交路径
                                                        success:function(data){
                                                            if(data.success){
                                                                $.messager.alert("提示", "恢复成功！", 'info');
                                                                $('#'+listDisplayEId).datagrid('reload');
                                                            }else{
                                                                $.messager.alert("提示", data.msg, 'warning');
                                                            }
                                                        },
                                                        error:function(){
                                                            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                                                        }
                                                    });
                                                }
                                                $('#'+listDisplayEId).datagrid('reload');
                                                $('#'+listDisplayEId).datagrid('clearSelections');
                                                });
                                            }
                                        }
                                    },
                                    {
                                        id : listDisplayEId + '_btn_del',
                                        text : '供货商材料拷贝',
                                        iconCls : 'icon-edit',
                                        handler : function() {
                                            
                                        	
                                        	if( $('#supId').combobox('getValue')==0){
                                                $.messager.alert('提示','请选择供货商！','info');
                                                return;
                                        	}
                                            var row = $('#'+listDisplayEId).datagrid('getSelections');      
                                            if(row.length == 0){
                                                $.messager.alert('提示','请选择一条记录操作！','info');
                                                return;
                                            }else{
                                                var str = "materId=" + row[0]['materId']+"&materLevel=" + row[0]['materLevel']+ "&supId=" + $('#supId').combobox('getValue')+ "&supIdCopy=" + row[0]['supId']; 
                                                $.messager.confirm('提示', '是否拷贝该条记录？', function(r){
                                                    if (r){         
                                                        $.ajax({type:'post',url:"<c:url value='/mater/copyMaterForSup.do'/>",data:str,dataType:"json",//设置查询参数及提交路径
                                                        success:function(data){
                                                            if(data.success){
                                                                $.messager.alert("提示", "拷贝成功！", 'info');
                                                                $('#'+listDisplayEId).datagrid('reload');
                                                            }else{
                                                                $.messager.alert("提示", data.msg, 'warning');
                                                            }
                                                        },
                                                        error:function(){
                                                            $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                                                        }
                                                    });
                                                }
                                                $('#'+listDisplayEId).datagrid('reload');
                                                $('#'+listDisplayEId).datagrid('clearSelections');
                                                });
                                            }
                                        }
                                    },
                                    {
                                        id : listDisplayEId + '_btn_save',
                                        text : '所有材料转换拼音',
                                        iconCls : 'icon-save',
                                        handler : function() {
                                            $.messager.confirm('提示', '是否所有材料转换拼音？', function(r){
                                                if (r){         
                                                    $.ajax({type:'post',url:"<c:url value='/mater/converterSpell.do'/>",data:{},dataType:"json",//设置查询参数及提交路径
                                                    success:function(data){
                                                        if(data.success){
                                                            $.messager.alert("提示", "处理成功！", 'info');
                                                            $('#'+listDisplayEId).datagrid('reload');
                                                        }else{
                                                            $.messager.alert("提示", data.msg, 'warning');
                                                        }
                                                    },
                                                    error:function(){
                                                        $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                                                    }
                                                });
                                            }
                                            $('#'+listDisplayEId).datagrid('reload');
                                            $('#'+listDisplayEId).datagrid('clearSelections');
                                            });
                                        }
                                    }
									,
									{
										id : listDisplayEId + '_btn_save',
										text : '备份当日菜单并生成采购的材料实际订单价格',
										iconCls : 'icon-save',
										handler : function() {
  											$.messager.confirm('提示', '是否备份当日菜单并生成采购的材料实际订单价格？', function(r){
												if (r){			
													$.ajax({type:'post',url:"<c:url value='/mater/backupAnddealOrdValue.do'/>",data:{},dataType:"json",//设置查询参数及提交路径
							 						success:function(data){
														if(data.success){
															$.messager.alert("提示", "处理成功！", 'info');
															$('#'+listDisplayEId).datagrid('reload');
														}else{
															$.messager.alert("提示", data.msg, 'warning');
														}
													},
									 				error:function(){
														$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
													}
												});
											}
											$('#'+listDisplayEId).datagrid('reload');
											$('#'+listDisplayEId).datagrid('clearSelections');
											});
										}
									},
									{
                                        id : listDisplayEId + '_btn_save',
                                        text : 'excel导出今日所有材料',
                                        iconCls : 'icon-save',
                                        handler : function() {
                                               excel();
                                        }
                                    },'-',
                                    {
                                        id : listDisplayEId + '_btn_edit',
                                        text : '材料图片',
                                        iconCls : 'icon-edit',
                                        handler : function() {
                                        
                                            var row = $('#'+listDisplayEId).datagrid('getSelections');
                                            if(row.length == 0){
                                                $.messager.alert('提示','请选择一条记录操作！','info');
                                                return;
                                            }else{
                                                var new_win = window.open("<c:url value='/jsp/openIndexSun.jsp?url=/photo/preMaterPhoto.do'/>"+"?materId="+row[0]['materId'] ,"sun","width=1200px,height=600px,status=no,scrollbars=yes");
                                                new_win.focus();
                                                $('#'+listDisplayEId).datagrid('reload');
                                            }
                                            $('#'+listDisplayEId).datagrid('clearSelections');
                                        }
                                    }
                                    
									],
							onLoadError:function(){
								$.messager.alert('错误','获取数据失败，请与管理员联系！','error');
							}
						 ,onClickRow:function(rowIndex){
								$(".myrad").prop("checked",false);
								$(".myrad").eq(rowIndex).prop("checked",true);
							} 
						});
			};
			$(document).ready(function() {
				initList('listDisplay');
			});
			 
		 
			//品级格式
			function formatMaterLevel(value,row,index,field){
				if(value=="1"){
					return "优";
				}else if(value=="2"){
					return "中";
				}else if(value=="3"){
					return "差";
				}
			}
			 
			function formatRadio(value,rowData,rowIndex){
				return value="<input type='radio' class='myrad'  name='radioMater' />";
			}
			 
	
			function excelIn(){
				
				 $('#excelForm').form('submit',
		 				{
		 					url:'<c:url value='/store/importBrandSort.do'/>', //查询提交路径
		 					onSubmit:function()//提交按钮相应函数
		 					{
		 						return $('#excelForm').form('validate');
		 					},
		 					success:function(data){
		 						data = eval( "("+data+")" );
		 		       			if(data.success){
		 		       				$.messager.alert("提示", "上传成功！", 'info');
		 	       				} else {
		 					        var message = "";
		 	       					if(data.msg == "msg007"){
		 	       						message = "excel 格式有问题 请检查。";
		 	       					}
		 	       					if(data.msg == "msg006"){
	 	       							message = "请检查供货商名称是否正确。";
	 	       						}
		 		       				$.messager.alert("提示", message, 'warning');
		 					    }
		 					},
		 					error:function(){
		 						$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
		 						return;
		 					}
		 				}); 
		 	 			
				
 			}
			function excel(){
                $('#excelForm').form('submit',
                        {
                            url:'<c:url value='/mater/exportMaterExcel.do'/>', //查询提交路径
                            onSubmit:function()//提交按钮相应函数
                            {
                                return $('#excelForm').form('validate');
                            },
                            success:function(data){
                                data = eval( "("+data+")" );
                                if(data.success){
                                    $.messager.alert("提示", "提交成功！",'info', function(){
                                        window.close();
                                    });
                                }else{
                                    $.messager.alert("提示", data.msg, 'warning');
                                }
                            },
                            error:function(){
                                $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                                return;
                            }
                        });
            }
			
			//下拉框
            $(function() {        
                $('#materType').combobox({   
                    url:"<c:url value='/mater/pulldownMaterType.do?space=1'/>",   
                    editable:true, //不可编辑状态  
                    cache: false,  
                    panelHeight: '150',  
                    valueField:'materType',     
                    textField:'materTypename',                      
                    }); 
                $('#supId').combobox({   
                    url:"<c:url value='/store/pulldownSupId.do?space=2'/>",   
                    editable:false, //不可编辑状态  
                    cache: false,  
                    valueField:'supId',     
                    textField:'supName',  
                    value:0
                });
            });
            function searchInfo(){
                if($('#materType').combobox('getValue') ==''){
                    $('#listDisplay').datagrid('load', {
                        materType : 0,
                        materName : $('#materName').val(),
                        supId : $('#supId').combobox('getValue')
                    }); 
                }else{
                    $('#listDisplay').datagrid('load', {
                        materType : $('#materType').combobox('getValue'),
                        materName : $('#materName').val(),
                        supId : $('#supId').combobox('getValue')
                    });  
                }
            }
            function tea(){
            	$('#listDisplay').datagrid('load');  
            }
            
            // 颜色
            function cellStyler(value, row, index) {
                if (row['deleteFlag'] == 1) {
                    return 'background-color:red;';
                }
            }
           
		</script>
			</head>
			<body>
			
			<object  id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 
                <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
            </object>
            
			<table width="98%">
			<tr>
		    <td>
			<div style="height: auto; width:1180px;background: #fafafa; padding: 5px;" class="easyui-panel" title="批量修改" iconCls="icon-add" collapsible="true" minimizable="false" maximizable="false" closable="false">
					<form id="excelForm" name="excelForm" method="post"  enctype="multipart/form-data"
						action="userlist.txt"
						onsubmit="return searchDGData(this.id,'listDisplay');">
						<div>
		            	<table cellpadding="5">
								<tr>
								
									<td>文件路径</td>
									<td><input class="easyui-filebox" name="filename" ></input></td>
		                    		<td><input type="button" onclick="excelIn()" value="批量修改原材料"></td>
		                    	</tr>
		                </table>					 
						</div>
					</form>
				</div>
			</td>
			</tr>
			<tr><td>
            <div style="height: auto; width:1180px;background: #fafafa; padding: 5px;" class="easyui-panel" title="查询" iconCls="icon-search" collapsible="true" minimizable="false" maximizable="false" closable="false">
                    <form id="searchForm" name="searchForm" method="post"
                        action="userlist.txt"
                        onsubmit="return searchDGData(this.id,'listDisplay');">
                        <div>
                        <table cellpadding="5">
                                <tr>
                                    <td>材料名：</td>
                                    <td><input class="easyui-validatebox" id="materName" editable="true" name="materName"></input></td>
                                    <td>类别：</td>
                                    <td><input class="easyui-combobox" id="materType" editable="false" name="materType"></input></td>
                                    <td>供货商：</td>
                                    <td><input class="easyui-combobox" name="supId" id="supId" editable="false"  /></td>
                                    <td><input type="button" onclick="searchInfo()" value="查询"></td>
                                </tr>
                        </table>                     
                        </div>
                    </form>
                </div>
            </td></tr>
			<tr>
			<td>
				<table id="listDisplay" title="材料列表" 
				iconCls="icon-list" singleSelect="true" idField="id"
				url="<c:url value="/mater/findMater.do"/>" loadMsg="请稍候......"
				pagination="true" pageSize="20"
				pageList="[10,20,30,40,50]" sortName="materId"
				rownumbers="true" sortOrder="asc">
				<thead>
				<tr>
				    <th field="materRole" width="25" align="center" formatter="formatRadio"  styler="cellStyler">
					</th> 
				    <th field="materId" width="80" formatter="formatDGField" sortable="true" editor="text" styler="cellStyler">
						材料ID
					</th>	
 					<th field="materName" width="80" formatter="formatDGField" sortable="true" editor="text" styler="cellStyler">
						材料名
					</th>
					<th field="unit" width="50" sortable="true" editor="text" styler="cellStyler">单位
                    </th>
                    <th field="brands" width="70" sortable="true" editor="text" styler="cellStyler">品牌
                    </th>  
                    <th field="specifications" width="70" sortable="true" editor="text" styler="cellStyler">规格
                    </th>   
					<th field="materType" width="80" formatter="formatFoodType1" sortable="true" editor="text" styler="cellStyler">
						种类
					</th>	
					<th field="materLevel" width="50" formatter="formatMaterLevel" sortable="true" editor="text" hidden="true" styler="cellStyler">
						品别
					</th>	
					<th field="supId" width="80"  sortable="true" editor="text" hidden="true" styler="cellStyler">
						供货商ID
					</th>	
					<th field="supName" width="100"  sortable="true" editor="text" styler="cellStyler">
						供货商名
					</th>
					<th field="materValue" width="60"  sortable="true" editor="text" styler="cellStyler">
						净料价格
					</th>	
					<th field="materValueUndressed" width="60"  sortable="true" editor="text" styler="cellStyler">
						毛料价格
					</th>	
					<th field="materProportion" width="60" formatter="formatDGField" sortable="true" editor="text" styler="cellStyler">
						毛料率
					</th>
					<th field="materDescribe" width="100" formatter="formatDGField" sortable="true" editor="text" styler="cellStyler">
						描述
					</th>
					<th field="deleteFlag" width="60"  sortable="true" formatter="formateDeleteFlag" editor="text" styler="cellStyler">删除标记
                    </th>
					
 				</tr>
				</thead>
			</table>
			</td>
			</tr>
		</table>
	</body>
</html>